package cn.matezk.cloud.dto;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Calendar;

@Data
public class BaseDto implements Serializable {
    protected Long userId;
    protected String deviceId;
    protected String date;
    protected String beginTime;
    protected String endTime;
    protected String key;
    protected Integer pageNo = 1;
    protected Integer pageSize = 20;

    public String getBeginTime() {
        return ObjectUtil.isNotEmpty(beginTime) ? beginTime : date;
    }

    public String getEndTime() {
        if (ObjectUtil.isEmpty(date))   return endTime;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(DateUtil.parseDate(date));
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        return DateUtil.format(calendar.getTime(), DatePattern.NORM_DATE_PATTERN);
    }
}
